package com.mes.basicdata.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

/**
 * <p>
 * 用于描述工艺BOM，对应数据库中的B_Bill_Of_Material
 * </p>
 * 
 * <p>
 * Created on 2017-03-17
 * </p>
 * 
 * @author lcs
 * 
 */
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "B_BILL_OF_MATERIALS")
@BatchSize(size=10)
@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class OperationPart extends BasicModel implements java.io.Serializable {

	// 连接编号
	@Id
	@GenericGenerator(name = "linkUid", strategy = "assigned")
	@Column(name="UNIQUEID")
	private String linkUid;
	
	// 工序
	@Column(name="OPUID")
	private String operationUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="OPUID",insertable=false,updatable=false)
	private Operation operation;
	
	// 消耗物料
	@Column(name="CONSUMED_PART_NUMBER")
	private String consumedPartUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="CONSUMED_PART_NUMBER",insertable=false,updatable=false)
	private Part consumedPart;
	
	// 产出物料编号
	@Column(name="PRODUCED_PART_NUMBER")
	private String producedPartUid;
	// 产出物料
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PRODUCED_PART_NUMBER",insertable=false,updatable=false)
	private Part producedPart;
	
	// 产生物料数量
	@Column(name="PRODUCED_QUANTITY",precision=25,scale=6)
	private Float producedQuantity;
	
	// 产出物料单位
	@Column(name="PRODUCED_QUANTITY_UOM",length=50)
	private String producedQuantityUom;
	
	// 消耗物料数量
	@Column(name="CONSUMED_QUANTITY",precision=25,scale=6)
	private Float consumedQuantity;
	
	// 消耗物料单位
	@Column(name="CONSUMED_QUANTITY_UOM",length=50)
	private String consumedQuantityUom;
	/*@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="CONSUMED_QUANTITY_UOM",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'uom'", referencedColumnName="TYPESNAME"))
	})
	private TypesData consumedQuantityUomDesc;*/
	
	//圆整类型
	@Column(name="ROUND_TYPE")
	private String roundType;
	
	// 消耗类型
	@Column(name="CONSUME_TYPE")
	private String consumedType;
	
	// 工艺编号
	@Column(name="ROUTING")
	private String routingUid;
	// 工艺
	@Transient
	private Routing routing;
	
//	// 工序排序号
//	@Column(name="OPERATION_ID",precision=10)
//	private Float operationId;
//	
//	// 最小固定损耗数量
//	@Column(name="MIN_FIXED_SHRINKAGE",precision=25,scale=6)
//	private Float minFixedShrinkage;
//	
//	// 最小损耗率
//	@Column(name="MIN_PERCENT_SHRINKAGE",precision=25,scale=6)
//	private Float minPercentShrinkage;
//	
//	// 是否虚拟件
//	@Column(name="PHANTOM", precision=2,scale=0)
//	private Long isPhantom;
//	
//	// 工程更改日期
//	@Column(name="ECN_DATE",length=7)
//	private Date engineeringChangeDate;
//	
//	// 工程更改描述
//	@Column(name="ECN_DESCRIPTION")
//	private String engineeringChangeDescription;
//	
//	// 工程更改日期格式
//	@Column(name="ECN_DATE_FORMAT",length=7)
//	private Date engineeringChangeDateFormat;
//	
//	// 工程更改号
//	@Column(name="ECN_CODE",length=10)
//	private String engineeringChangeCode;
//	
//	// 工程更改级别
//	@Column(name="ECN_LEVEL",precision=10,scale=0)
//	private Long engineeringChangeLevel;
//	
//	// 工程更改编号
//	@Column(name="ECN_NUMBER",precision=10,scale=0)
//	private Long engineeringChangeNumber;
//	
//	// 能否被新制造订单所用  
//	@Column(name="USABLE_BY_NEW_MFG_ORDER",precision=2,scale=0)
//	private Long usableByNewMfgOrder;
//	
	// 正常损耗率
	@Column(name="NORM_PERCENT_SHRINKAGE",precision=25,scale=6)
	private Float normalPercentShrinkage;
//	
	// 正常损耗数量
	@Column(name="NORM_FIXED_SHRINKAGE",precision=25,scale=6)
	private Float normalFixedShrinkage;
//	
//	// 最小数量
//	@Column(name="MIN_QUANTITY",precision=25,scale=6)
//	private Float minQuantity;
//	
//	// 过程
//	@Column(name="PROCESS",length=50)
//	private String process;
//	
//	// 数量限制类型
//	@Column(name="QUANTITY_CONSTRAINT_TYPE",length=50)
//	private String quantityConstraintType;
//	
//	// 弹性最小数量
//	@Column(name="FLEXIBLE_MIN_QUANTITY_P",precision=2,scale=0)
//	private Long flexibleMinQuantityP;
//	
//	// 最大数量
//	@Column(name="MAX_QUANTITY",precision=25,scale=6)
//	private Float maxQuantity;
//	
//	// 倍数
//	@Column(name="MULTIPLE_QUANTITY",precision=25,scale=6)
//	private Float multipleQuantity;
//	
//	// 消耗属性
//	@Column(name="ATTRIBUTE_CONSUMED",length=50)
//	private String attributeConsumed;
//	
//	// 产生属性
//	@Column(name="ATTRIBUTE_PRODUCED",length=50)
//	private String attributeProduced;
//	
//	// 是否有效
//	@Column(name="EFFECTIVE",precision=2,scale=0)
//	private Boolean effective;
//	
//	//PBOM生效日期
//	@Column(name="P_BEGINDAY",length=7)
//	private Date pbomBeginday;
//	
//	//PBOM失效日期
//	@Column(name="P_ENDDAY",length=7)
//	private Date pbomEndday;
//	
//	//EBOM生效日期
//	@Column(name="E_BEGINDAY",length=7)
//	private Date ebomBeginday;
//	
//	//EBOM失效日期
//	@Column(name="E_ENDDAY",length=7)
//	private Date ebomEndday;
//	
//	//PBOM单号
//	@Column(name="P_BOMNUMBER")
//	private String pbomNo;
//	
//	//eBOM单号
//	@Column(name="E_BOMNUMBER")
//	private String ebomNo;
//		
//	//sf_path三维模型访问路径
//	@Column(name="SF_PATH")
//	private String sfpath;
//	
//	@Column(name="IS_CRITICAL",precision=2, scale=0)
//	private Long isCritical;
//	
//	@Column(name="READYPOINT",precision=2, scale=0)
//	private Long readyPoint;
	
	/** default constructor */
	public OperationPart() {
	}
	
	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getLinkUid();
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setLinkUid(uuid);
	}

	public String getLinkUid() {
		return linkUid;
	}

	public void setLinkUid(String linkUid) {
		this.linkUid = linkUid;
	}

	public String getConsumedPartUid() {
		return consumedPartUid;
	}

	public void setConsumedPartUid(String consumedPartUid) {
		this.consumedPartUid = consumedPartUid;
	}

	public String getProducedPartUid() {
		return producedPartUid;
	}

	public void setProducedPartUid(String producedPartUid) {
		this.producedPartUid = producedPartUid;
	}

	public Part getConsumedPart() {
		return consumedPart;
	}

	public void setConsumedPart(Part consumedPart) {
		this.consumedPart = consumedPart;
	}

	public Part getProducedPart() {
		return producedPart;
	}

	public void setProducedPart(Part producedPart) {
		this.producedPart = producedPart;
	}

	public String getOperationUid() {
		return operationUid;
	}

	public void setOperationUid(String operationUid) {
		this.operationUid = operationUid;
	}

	public Operation getOperation() {
		return operation;
	}

	public void setOperation(Operation operation) {
		this.operation = operation;
	}

	public String getRoutingUid() {
		return routingUid;
	}

	public void setRoutingUid(String routingUid) {
		this.routingUid = routingUid;
	}

	public Routing getRouting() {
		return routing;
	}

	public void setRouting(Routing routing) {
		this.routing = routing;
	}


	public String getProducedQuantityUom() {
		return producedQuantityUom;
	}

	public void setProducedQuantityUom(String producedQuantityUom) {
		this.producedQuantityUom = producedQuantityUom;
	}

	public String getConsumedQuantityUom() {
		return consumedQuantityUom;
	}

	public void setConsumedQuantityUom(String consumedQuantityUom) {
		this.consumedQuantityUom = consumedQuantityUom;
	}

	public String getRoundType() {
		return roundType;
	}

	public void setRoundType(String roundType) {
		this.roundType = roundType;
	}

	public String getConsumedType() {
		return consumedType;
	}

	public void setConsumedType(String consumedType) {
		this.consumedType = consumedType;
	}

	public Float getProducedQuantity() {
		return producedQuantity;
	}

	public void setProducedQuantity(Float producedQuantity) {
		this.producedQuantity = producedQuantity;
	}

	public Float getConsumedQuantity() {
		return consumedQuantity;
	}

	public void setConsumedQuantity(Float consumedQuantity) {
		this.consumedQuantity = consumedQuantity;
	}

	public Float getNormalPercentShrinkage() {
		return normalPercentShrinkage;
	}

	public void setNormalPercentShrinkage(Float normalPercentShrinkage) {
		this.normalPercentShrinkage = normalPercentShrinkage;
	}

	public Float getNormalFixedShrinkage() {
		return normalFixedShrinkage;
	}

	public void setNormalFixedShrinkage(Float normalFixedShrinkage) {
		this.normalFixedShrinkage = normalFixedShrinkage;
	}

}